package com.sky.service.impl;

import com.sky.constant.MessageConstant;
import com.sky.dto.UserLoginDTO;
import com.sky.entity.AddressBook;
import com.sky.entity.User;
import com.sky.exception.LoginFailedException;
import com.sky.mapper.AddressBookMapper;
import com.sky.mapper.UserMapper;
import com.sky.service.AddressBookService;
import com.sky.service.UserService;
import com.sky.utils.WeChatLoginUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Service
@AllArgsConstructor
public class AddressBookServiceImpl implements AddressBookService {
    private final Integer DEFAULT = 0;
    private final Integer isDEFAULT= 1;

    @Autowired
    private AddressBookMapper addressBookMapper;

    public List<AddressBook> list(AddressBook addressBook) {
        return addressBookMapper.selectAllAddresses(addressBook);
    }

    public void insertAddress(AddressBook addressBook) {
        addressBook.setIsDefault(DEFAULT);
        addressBookMapper.insert(addressBook);
    }

    public AddressBook getAddressBookById(AddressBook addressBook) {
        return addressBookMapper.getAddressById(addressBook);
    }

    public void updateAddressById(AddressBook addressBook) {
        updateAddressById(addressBook);
    }


    public void deleteAddressById(AddressBook addressBook) {
        addressBookMapper.deleteAddressById(addressBook);
    }

    public AddressBook getIsDefaultTAddresses(AddressBook addressBook) {
        return addressBookMapper.getIsDefaultTAddresses(addressBook);
    }

    public void isDefault(AddressBook addressBook) {
        addressBook.setIsDefault(DEFAULT);
        addressBookMapper.setDefaultByUserId(addressBook);

        addressBook.setIsDefault(isDEFAULT);
        addressBookMapper.updateAddressById(addressBook);
    }
}
